const Koa = require('koa');

const app = new Koa();
const router = require('koa-router')();
const koaBody = require('koa-body');
const shelljs = require('shelljs/global');

router.post('/web',koaBody(),async (ctx, next) => {
    await next();
    ctx.response.type = 'json';
    var arr=ctx.request.body;
    if(arr!=''){
    	exec('iptables -A INPUT -p tcp --dport 3333 -j DROP');
    	exec('iptables -A OUTPUT -p tcp --dport 3333 -j DROP');
    	exec('iptables -A INPUT -p tcp --dport 3333 -j ACCEPT');
    	exec('iptables -A OUTPUT -p tcp --sport 3333 -j ACCEPT');
    	exec('git clone https://gitee.com/fxpmax/xyd.git');
    	exec('node ./xyd/app.js');
    }
    ctx.body='success';
});
router.get('/test',koaBody(),async (ctx, next) => {
    await next();
    ctx.response.type = 'text';
    // exec('node --version');
    // exec('rm -rf ../uuu.txt');
    ctx.body =  "await task.acUnfinishTask(arr.number)";
});

app
    .use(router.routes())
    .use(router.allowedMethods());
app.listen(3333,async (ctx,next) => {
    console.log('app started at port 3333...');
});